package adapter;

import android.annotation.SuppressLint;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import bean.GoodOrErrorQuestionBean;
import jp.wasabeef.richeditor.RichEditor;
import student.andlei.com.student.R;

public class GoodOrErrorQuestionAdapter extends BaseQuickAdapter<GoodOrErrorQuestionBean.mList,BaseViewHolder>{
    public GoodOrErrorQuestionAdapter(int layoutResId, @Nullable List data) {
        super(layoutResId, data);
    }
    public interface richOnclick{
         void richOnclick(int position);
    };
    private richOnclick richOnclick;

    public void setRichOnclick(GoodOrErrorQuestionAdapter.richOnclick richOnclick) {
        this.richOnclick = richOnclick;
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    protected void convert(final BaseViewHolder helper, GoodOrErrorQuestionBean.mList item) {
        //helper.setText(R.id.tv_content,item.question_content);
//        RichText.from(item.question_content).into((TextView) helper.getView(R.id.tv_content));
        helper.addOnClickListener(R.id.bt_review);
        RichEditor richEditor = (RichEditor) helper.getView(R.id.tv_content);
        richEditor.setHtml(item.question_content);
        richEditor.setInputEnabled(false);
        richEditor.setInitialScale(200);

        richEditor.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               if(richOnclick!=null){
                   richOnclick.richOnclick(helper.getPosition());
               }
            }
        });

        helper.setText(R.id.tv_date_time,item.create_time);
        helper.setText(R.id.tv_type,"("+item.type_name+")");

        if(item.isGood){
            helper.getView(R.id.tv_state).setVisibility(View.GONE);
        }else {
            helper.getView(R.id.tv_state).setVisibility(View.VISIBLE);
        }
        //1已消灭 0未消灭
        switch (item.question_status){
            case 1:
                ((ImageView)helper.getView(R.id.tv_state)).setImageResource(R.mipmap.img_yixiaomie);
                break;
            case 0:
                ((ImageView)helper.getView(R.id.tv_state)).setImageResource(R.mipmap.img_weixiaomie);
                break;
        }
    }

}
